﻿// ActionScript file
/**
 * Stage的代理引用类
 */
package org.nickro.utils{
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	public class StageProxy extends EventDispatcher
	{
		private var _instance:StageProxy;
		private var _stage:Stage;
		private static var _allowInstance:Boolean = false;
		public function StageProxy()
		{
			if(!StageProxy._allowInstance)
			{
				throw new Error("Error: Use StageControl.getInstance() instead of the new keyword.");
			}
		}
		
		public static function getInstance():StageProxy
		{
			if( _instance == null)
			{
				StageProxy._allowInstance = true;
				_instance = new StageProxy();
				StageProxy._allowInstance = false;
			}
			return _intance;
		}
		
		public function addStage(value:Stage):void
		{
			if(_stage == null)
			{
				_stage = value;
				_stage.addEventListener(Event.ACTIVATE,onResize);
				_stage.addEventListener(Event.RESIZE,onResize);
			}
		}
		
		private function onResize(e:Event):void
		{
			
		}
		
		public function get stage():Stage
		{
			if(_stage != null)
			{
				return _stage;
			}else
			{
				throw new Error("stage isn't added to StageControl");
			}			
		}
	}
}